<?php
/**
 * @author 天涯 <mail@phpha.com>
 * @copyright http://blog.phpha.com
 * @link http://blog.phpha.com/vncms
 * @version 1.0
 */
defined('APP_PATH') or exit('Access Denied');
require 'check.php';
class ucat extends check{
	//分组列表
	public function lis(){
		$this->ucat = spClass('m_ucat')->findAll(null, 'id ASC');
		$this->display('ucat_lis.tpl.php');
	}
	//添加分组
	public function add(){
		$this->display('ucat_add.tpl.php');
	}
	public function doadd(){
		if(false != spClass('m_ucat')->spVerifier($this->spArgs()))	$this->error('数据验证错误！',spUrl('ucat','add'));
		if(false != spClass('m_ucat')->create($this->spArgs())){
			$this->success('添加分组成功！',spUrl('ucat','lis'));
		}else{
			$this->error('添加分组失败！',spUrl('ucat','add'));
		}
	}
	//更新分组
	public function upd(){
		if(!$id = intval($this->spArgs('id')))	$this->error('缺少必要参数！',spUrl('ucat','lis'));
		$this->ucrow = spClass('m_ucat')->find(array('id'=>$id));
		$this->display('ucat_upd.tpl.php');
	}
	public function doupd(){
	if(false != spClass('m_ucat')->spVerifier($this->spArgs()))	$this->error('数据验证错误！',spUrl('ucat','lis'));
		$ucrow = $this->spArgs();
		if(false != spClass('m_ucat')->update(array('id'=>$ucrow['id']),$ucrow)){
			$this->success('更新分组成功！',spUrl('ucat','lis'));
		}else{
			$this->error('更新分组失败！',spUrl('ucat','lis'));
		}
	}
	//删除分组
	public function del(){
	if(!$id = intval($this->spArgs('id')))	$this->error('缺少必要参数！',spUrl('ucat','lis'));
		if(false != spClass('m_user')->find(array('groupid'=>$id))){
			$this->error('该分组下存在会员禁止删除！',spUrl('ucat','lis'));
		}elseif(false != spClass('m_ucat')->delete(array('id'=>$id))){
			$this->success('删除分组成功！',spUrl('ucat','lis'));
		}else{
			$this->error('删除分组失败！',spUrl('ucat','lis'));
		}
	}
}